function once(func){
  let flag = false,res
  return function(){
  
    if(flag==true){
      return res
    }else {
      flag = true 
      res = func()
      // func = null
      return res
    }
   
  }
}
let i=0;
let foo = once(()=>{
  i++
  return i
});

console.log(foo());
console.log(foo());